<?
function get_by_curl($url,$post='',$vars='',$user_agent=''){
	if(!$user_agent) $user_agent="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6";
    $ch = curl_init(); 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);  
if($post){
	curl_setopt ($ch , CURLOPT_POST , 1) ; 
	curl_setopt ($ch, CURLOPT_POSTFIELDS, $vars); 
}
    curl_setopt ($ch, CURLOPT_HEADER, 1);

	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
    $result = curl_exec ($ch);
    curl_close($ch);
return $result;
}

function get_head_curl($url,$time=10){
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt ($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT,$time);

$r = curl_exec($ch);

return $r;
}

if($_GET['ytb']){
				
	$videoid[1]=trim($_GET['ytb']);
	$url="http://www.youtube.com/?v=".$videoid[1];			
	$data=get_by_curl($url);
	preg_match('# "t": "(.*?)"#', $data, $t_mat);
	$video = 'http://www.youtube.com/get_video?video_id='.$videoid[1].'&t='.$t_mat[1].'&el=detailpage&ps=&fmt=5';
	$flv=get_head_curl($video);
	preg_match("#Location:(.*?)\\n#s",$flv, $cut);
	$url=trim($cut[1]);
	header("Location: ".$url);
}

if($_GET['gg']){
	
	$id[1]=trim($_GET['gg']);
	$url_get='http://video.google.com/videoplay?docid='.$id[1];
	$data=get_by_curl($url_get);
	$parse=explode("googleplayer.swf?videoUrl",$data);
	$parse=explode("thumbnailUrl",$parse[1]);
	$google=urldecode($parse[0]);
	$google=str_replace('\x2F','/',$google);
	$google=str_replace('\x3d','',$google);
	$google=str_replace('\x26','',$google);
	$url=$google;
	header("Location: ".$url);

}

?>